Fix #30690: Preserve newlines in import_yaml multi-line scalars#68535
Open
dwoz wants to merge 1 commit intosaltstack:3006.xfrom
Open
Fix #30690: Preserve newlines in import_yaml multi-line scalars#68535dwoz wants to merge 1 commit intosaltstack:3006.xfrom
dwoz wants to merge 1 commit intosaltstack:3006.xfrom
Conversation
bdrx312
reviewed
Dec 15, 2025
| return [_unescape_newlines(item) for item in data] | ||
| elif isinstance(data, str): | ||
| # Convert literal \n (backslash-n) to actual newline | ||
| return data.replace("\\n", "\n") |
Contributor
There was a problem hiding this comment.
What happens if someone had escaped the \ in the data like \\n? With this change is there a way to get a literal \n anymore?
Contributor
There was a problem hiding this comment.
What happens on Windows? Does it need to also look for \\r\\n? Maybe need to use os.linesep instead?
bdrx312
reviewed
Dec 15, 2025
| from salt.loader.context import NamedLoaderContext | ||
| from salt.loader.dunder import __file_client__ | ||
| from salt.utils.decorators.jinja import JinjaFilter, JinjaGlobal, JinjaTest | ||
| from salt.utils.odict import OrderedDict |
Contributor
There was a problem hiding this comment.
This doesn't look right. Wasn't odict deprecated?
When using import_yaml to load YAML data with multi-line scalars (using |), the newlines were being rendered as literal \n instead of actual newlines when passed through Jinja templates. This fix adds an _unescape_newlines function that recursively converts literal \n sequences back to actual newlines in the context dictionary before it's used for templating. - Added _unescape_newlines function to salt/utils/templates.py - Applied unescape to context before creating decoded_context - Updated test to remove to_dict filter reference
9c90944 to
09b9b95
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using import_yaml to load YAML data with multi-line scalars (using |), the newlines were being rendered as literal \n instead of actual newlines when passed through Jinja templates.
This fix adds an _unescape_newlines function that recursively converts literal \n sequences back to actual newlines in the context dictionary before it's used for templating.
Fixes #30690